package engine.input;

import javafx.scene.input.KeyCode;

public enum Key {
    NUM0(KeyCode.DIGIT0, "0"),
    NUM1(KeyCode.DIGIT1, "1"),
    NUM2(KeyCode.DIGIT2, "2"),
    NUM3(KeyCode.DIGIT3, "3"),
    NUM4(KeyCode.DIGIT4, "4"),

    Q(KeyCode.Q, "Q"),
    W(KeyCode.W, "W"),
    E(KeyCode.E, "E"),
    P(KeyCode.P, "P"),

    A(KeyCode.A, "A"),
    S(KeyCode.S, "S"),
    D(KeyCode.D, "D"),
    F(KeyCode.F, "F"),

    Z(KeyCode.Z, "Z"),
    X(KeyCode.X, "X"),
    C(KeyCode.C, "C"),

    UP(KeyCode.UP, "Up"),
    DOWN(KeyCode.DOWN, "Down"),
    LEFT(KeyCode.LEFT, "Left"),
    RIGHT(KeyCode.RIGHT, "Right"),

    Enter(KeyCode.ENTER, "Enter"),
    ESCAPE(KeyCode.ESCAPE, "Esc"),
    TAB(KeyCode.TAB, "Tab"),
    SHIFT(KeyCode.SHIFT, "Shift"),
    CONTROL(KeyCode.CONTROL, "Ctrl"),
    SPACE(KeyCode.SPACE, "Space"),
    ALT(KeyCode.ALT, "Alt"),


    nul(null, "null");


    private final KeyCode code;
    private final String text;

    Key(KeyCode keyCode, String text) {
        this.code = keyCode;
        this.text = text;
    }

    public static Key find(KeyCode keyCode) {//根据键盘按键查找枚举
        for (Key k : values()) {
            if (k.code == keyCode && k.code != null) {
                return k;
            }
        }
        return null;
    }


    public static Key find(String text) {
        for (Key key : values()) {
            if (key.text != null && key.text.equalsIgnoreCase(text)) {
                return key;
            }
        }
        return null;
    }
}
